CREATE TABLE [dbo].[PaymentMain]
(
[PaymentKey] [uniqueidentifier] NOT NULL,
[Amount] [decimal] (18, 4) NOT NULL CONSTRAINT [DF_PaymentMain_Amount] DEFAULT ((0)),
[PaymentApplicationRestrictionCode] [int] NULL,
[FinancialEntityKey] [uniqueidentifier] NOT NULL,
[PaymentDate] [datetime] NOT NULL,
[AmountHome] [decimal] (18, 4) NULL,
[CurrencyCode] [nchar] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[OriginalPaymentKey] [uniqueidentifier] NULL,
[PayorContactKey] [uniqueidentifier] NOT NULL,
[SummaryDisplay] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[AccessKey] [uniqueidentifier] NOT NULL,
[CreatedByUserKey] [uniqueidentifier] NOT NULL,
[CreatedOn] [datetime] NOT NULL,
[UpdatedByUserKey] [uniqueidentifier] NOT NULL,
[UpdatedOn] [datetime] NOT NULL,
[SystemEntityKey] [uniqueidentifier] NOT NULL,
[OwnerGroupKey] [uniqueidentifier] NULL,
[PaymentMethodKey] [uniqueidentifier] NULL,
[PaymentReferenceData] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[PaymentDetailKey] [uniqueidentifier] NULL,
[MarkedForDeleteOn] [datetime] NULL,
[FinalBatchKey] [uniqueidentifier] NULL,
[OriginatingBatchKey] [uniqueidentifier] NULL,
[BatchLineStatusCode] [int] NULL,
[BatchStatusMessage] [nvarchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[PaymentMain] ADD CONSTRAINT [PK_PaymentMain] PRIMARY KEY CLUSTERED ([PaymentKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_PaymentMain_PayorContactKey] ON [dbo].[PaymentMain] ([PayorContactKey]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[PaymentMain] ADD CONSTRAINT [FK_PaymentMain_AccessMain] FOREIGN KEY ([AccessKey]) REFERENCES [dbo].[AccessMain] ([AccessKey])
GO
ALTER TABLE [dbo].[PaymentMain] ADD CONSTRAINT [FK_PaymentMain_ContactMain_Payor] FOREIGN KEY ([PayorContactKey]) REFERENCES [dbo].[ContactMain] ([ContactKey])
GO
ALTER TABLE [dbo].[PaymentMain] ADD CONSTRAINT [FK_PaymentMain_GroupMain_Owner] FOREIGN KEY ([OwnerGroupKey]) REFERENCES [dbo].[GroupMain] ([GroupKey])
GO
ALTER TABLE [dbo].[PaymentMain] ADD CONSTRAINT [FK_PaymentMain_PaymentApplicationRestrictionRef] FOREIGN KEY ([PaymentApplicationRestrictionCode]) REFERENCES [dbo].[PaymentApplicationRestrictionRef] ([PaymentApplicationRestrictionCode])
GO
ALTER TABLE [dbo].[PaymentMain] ADD CONSTRAINT [FK_PaymentMain_PaymentMain_Original] FOREIGN KEY ([OriginalPaymentKey]) REFERENCES [dbo].[PaymentMain] ([PaymentKey])
GO
ALTER TABLE [dbo].[PaymentMain] ADD CONSTRAINT [FK_PaymentMain_SystemEntity] FOREIGN KEY ([SystemEntityKey]) REFERENCES [dbo].[SystemEntity] ([SystemEntityKey])
GO
ALTER TABLE [dbo].[PaymentMain] ADD CONSTRAINT [FK_PaymentMain_UniformRegistry] FOREIGN KEY ([PaymentKey]) REFERENCES [dbo].[UniformRegistry] ([UniformKey])
GO
ALTER TABLE [dbo].[PaymentMain] ADD CONSTRAINT [FK_PaymentMain_UserMain_CreatedBy] FOREIGN KEY ([CreatedByUserKey]) REFERENCES [dbo].[UserMain] ([UserKey])
GO
ALTER TABLE [dbo].[PaymentMain] ADD CONSTRAINT [FK_PaymentMain_UserMain_UpdatedBy] FOREIGN KEY ([UpdatedByUserKey]) REFERENCES [dbo].[UserMain] ([UserKey])
GO